package org.example.design.strategy;

/**
 * @author huangshen
 * @version 0
 * @description Sorter
 * @since 2022/2/6 22:06
 */
public class Sorter {

    /**
     * 选择排序
     * @param arr
     */
    public void sort(int[] arr) {

        for (int i = 0; i < arr.length - 1; i++) {
            int minPos = i;
            for (int j = i + 1; j < arr.length; j++) {
                minPos = arr[j] < arr[minPos] ? j : minPos;
            }
            swap(arr, i , minPos);
        }
    }

    private void swap(int[] arr, int i, int j) {
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }
}
